/* See LICENSE for copyright and terms of use */

import org.evtmng.tween.Tween;
import org.evtmng.events.IRunListener;
import org.evtmng.events.TweenEventInfo;

/**
 * @author Tay Ray Chuan
 */

class org.evtmng.tween.TweenHolder implements IRunListener {
	private var m_tween:Tween;
	private var m_obj:Object;
	private var m_prop:String;

	private var m_begin:Number;
	private var m_change:Number;
	private var m_easer:Function;

	public function TweenHolder() {
		m_begin = 0;
		m_change = 0;
	}

	public function initWithStartEnd(start:Number, end:Number) {
		m_tween = new Tween(start, end);
		return this;
	}

	public function initWithObjectPropertyBeginChange(
		object:Object, property:String,
		begin:Number, change:Number):TweenHolder {

		setObject(object);
		setProperty(property);
		setBegin(begin);
		setChange(change);

		return this;
	}

	public function setTween(f:Tween):Void {
		m_tween = f;
	}

	public function tween():Tween {
		return m_tween;
	}

	public function setObject(f:Object):Void {
		m_obj = f;
	}

	public function object():Object {
		return m_obj;
	}

	public function setProperty(f:String):Void {
		m_prop = f;
	}

	public function property():String {
		return m_prop;
	}

	public function setBegin(f:Number):Void {
		m_begin = f;
	}

	public function begin():Number {
		return m_begin;
	}

	public function setChange(f:Number):Void {
		m_change = f;
	}

	public function change():Number {
		return m_change;
	}

	public function setEaser(f:Function):Void {
		m_easer = f;
	}

	public function easer():Function {
		return m_easer;
	}

	public function valueAtTime(time:Number):Number {
		return m_easer(time, m_begin, m_change, m_tween.duration());
	}

	public function whileRunningTween(info:TweenEventInfo):Void {
		m_obj[m_prop] = valueAtTime(info.time());
	}
}